package cn.zyzpp.service.resume.impl;

import cn.zyzpp.dao.MySelfDao;
import cn.zyzpp.entity.resume.MySelf;
import cn.zyzpp.service.resume.MySelfService;
import cn.zyzpp.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Create by yster@foxmail.com 2018/5/21/021 22:49
 */
@Service
@CacheConfig(cacheNames = {"MySelfService"})
public class MySelfServiceImpl implements MySelfService {
    @Autowired
    private MySelfDao mySelfDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(MySelf mySelf, int uid) {
        mySelf.setUid(uid);
        mySelf.setSelfEvaluation(StringUtil.symline(mySelf.getSelfEvaluation()));
        mySelfDao.save(mySelf);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delect(int id) {
        mySelfDao.deleteAllById(id);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataByUid(MySelf mySelf) {
        MySelf mySelf1 = mySelfDao.findAllByUid(mySelf.getUid());
        mySelf.setSelfEvaluation(StringUtil.symline(mySelf.getSelfEvaluation()));
        mySelf1.updata(mySelf);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public MySelf query(int uid) {
        return mySelfDao.findAllByUid(uid);
    }
}
